﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Practices.Composite.Modularity;
using Microsoft.Practices.Composite.UnityExtensions;
using RiaCrm.EditRecord;
using RiaCrm.Infrastructure;
using Microsoft.Practices.Unity;
using System.Collections.Generic;
using Acando.Dynamics.CRM.Silverlight.Library.Helper;
using Acando.Dynamics.CRM.Silverlight.Library.Interfaces;
using RiaCrm.DataAccessLayer;

namespace RiaCrm.Shell
{
    public class Bootstrapper : UnityBootstrapper
    {
        public Dictionary<string, string> initParaDict { get; set; }

        protected override DependencyObject CreateShell()
        {
            Shell shell = new Shell();
            Application.Current.RootVisual = shell;

            return shell;
        }

        protected override void ConfigureContainer()
        {
            /* The app might be called with or without parameter:*/

            //String statedEntity = "contact";  // Default
            String statedEntity = "account";    // Default
            String statedOrga = "SAPSales";     // Default

            if (this.initParaDict.ContainsKey("entity"))
                statedEntity = initParaDict["entity"];

            if(this.initParaDict.ContainsKey("organame"))
                statedOrga = initParaDict["organame"];

            // befand sich vorher im DynamicEntityGrid Module:
            Container.RegisterType<IMetaDataLayer, MetaDataLayer>(new ContainerControlledLifetimeManager());

            Container.RegisterInstance(new InitParaEntityname { Value = statedEntity }, new ContainerControlledLifetimeManager());
            Container.RegisterInstance(new InitParaOrgaName { Value = statedOrga }, new ContainerControlledLifetimeManager());

            base.ConfigureContainer();
        }

        protected override Microsoft.Practices.Composite.Modularity.IModuleCatalog GetModuleCatalog()
        {
            ModuleCatalog catalog = new ModuleCatalog();
            catalog.AddModule(typeof(RiaCrm.Searching.SearchingModule));
            catalog.AddModule(typeof(RiaCrm.DynamicEntityGrid.DynamicEntityModule));
            catalog.AddModule(typeof(RiaCrm.EditRecord.EditRecordModule));
            catalog.AddModule(typeof(RiaCrm.IsolationStorage.IsolationStorageModule));
            catalog.AddModule(typeof(RiaCrm.Sitemap.SitemapModule));
            
        
            return catalog;
        }
    }
}
